package com.base.myproject.client.HR.attendance;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.tools.Tools;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxX;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;

/**
 * @author cxghiu410@gmail.com
 * 考勤机类型设置
 */
public class AttTypeSet extends BaseJDBCPanel {
	public AttTypeSet() {
		init();
	}

	public void init() {
		initWeigetx();
		registerMainStore(store);
	}
	
	public void complete() {
		super.complete();
	}

	public void initWeigetx() {
		VerticalPanel v = new VerticalPanel();
		v.setSpacing(2);
		v.add(createGrid());
		this.add(v);
	}

	BaseStore<BusiObject> store = null;

	BaseStore<BusiObject> getStore() {
		if (store == null) {
			createStore();
		}
		return store;
	}

	void createStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("sensorid");
		type.getField("sensorid").setType(String.class);
		type.addField("ip");
		type.getField("ip").setType(String.class);
		type.addField("touse");
		type.getField("touse").setType(String.class);
		type.addField("remark");
		type.getField("remark").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("hr_Attendance_type_setting");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from hr_Attendance_type_setting");
		store = new BaseStore<BusiObject>(type, info);
		
	}

	BaseGrid grid = null;

	BaseGrid createGrid() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		ColumnConfig C2 = new ColumnConfig("sensorid", "设备ip", 100);
		C2.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C2);
		
		ColumnConfig C3 = new ColumnConfig("ip", "ip地址", 140);
		C3.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C3);
		
		ColumnConfig C4 = new ColumnConfig("touse", "设置用途", 100);
		BaseComboBoxX bc4 = new BaseComboBoxX("name","dictionary", "where type='kc_type'");
		C4.setEditor(bc4.getCellEditor());
		columns.add(C4);
		
		ColumnConfig C5 = new ColumnConfig("remark", "备注", 220);
		C5.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C5);

		ColumnModel cm = new ColumnModel(columns);
		grid = new BaseGrid(getStore(), cm, true, true);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		grid.setSelectionModel(cbs);
		//grid.setSize(851, 380);
		Tools.setResize(grid, 1.00, 0.94);
		return grid;
	}
}
